<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/20
 * Time: 8:57
 * @author: yfl
 * @QQ: 554665488
 * @description:
 * @time:
 */

namespace app\admin\controller;


use app\oa\controller\CommonController;
use app\oa\logic\User as UserLogicModel;
use think\Request;
use think\Session;

class LoginController extends CommonController
{
    public function login(Request $request)
    {
        if ($request->isGet()) {

            return $this->fetch('login/login');
        }

        if ($request->isAjax()) {
            $data = $request->post();
            $res = UserLogicModel::login($data);
            if (is_object($res)) {
                if (!Session::has('admin_user', 'admin')) {
                    Session::set('admin_user', $res, 'admin');
                }
                return self::showReturnCodeWithOutData('loginSuccess', '登录成功...');
//                $this->redirect('/report');
            } else {
                self::toSaveLog(404, '保存日志');
                return self::showReturnCodeWithOutData(-1, $res);
            }
        } else {
            return self::showReturnCodeWithOutData(404);
        }
    }

    public function logout()
    {
        if (Session::has('admin_user', 'admin')) {
            Session::delete('admin_user','admin');
        }
        $this->redirect('/Alogin');
    }


}